#ifndef __SYSTECH_CRC_QUEUE_H__
#define __SYSTECH_CRC_QUEUE_H__

#include <stdbool.h>
#include <stdint.h>

#define DEFAULT_QUEUE_SIZE 5  // 最大任务队列大小
#define DEFAULT_FRAME_SIZE 96 // 任务帧大小

typedef struct
{
    uint8_t *buffer;
    uint16_t length;
} data_buffer;

typedef struct
{
    int          head;
    int          tail;
    int          size;
    int          max_size;
    int          max_buffer_size;
    data_buffer *queue;
} circular_queue_t;

// 错误码
typedef enum
{
    TASK_QUEUE_SUCCESS = 0,
    TASK_QUEUE_FULL,         // 队列已满
    TASK_QUEUE_EMPTY,        // 队列为空
    TASK_QUEUE_INVALID_DATA, // 数据无效
    TASK_QUEUE_NULL_POINTER, // 指针为空
    TASK_QUEUE_INIT_ERROR,   // 初始化错误
} circular_queue_error_t;

circular_queue_error_t circular_queue_init(circular_queue_t *q, const int queue_size, const int buffer_size);
circular_queue_error_t circular_queue_push(circular_queue_t *q, const data_buffer *cmd);
circular_queue_error_t circular_queue_pop(circular_queue_t *q, data_buffer *cmd);
circular_queue_error_t circular_queue_peek(circular_queue_t *q, data_buffer *task_data);
circular_queue_error_t circular_queue_destroy(circular_queue_t *q);
int circular_queue_remaining(circular_queue_t *q);
int circular_queue_size(circular_queue_t *q);

#endif
